<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div id="editForm" >
    <form class="layui-form" lay-filter="editForm">
        <!-- Existing form items -->

        <div class="layui-form-item">
            <label class="layui-form-label">原密码</label>
            <div class="layui-col-md2">
                <input type="password" name="oldPassword" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">新密码</label>
            <div class="layui-col-md2">
                <input type="password" name="newPassword" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">确认密码</label>
            <div class="layui-col-md2">
                <input type="password" name="confirmPassword" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>

        <!-- Remaining form items -->

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </form>


</div>



<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0"></script>

<script>


    var data;
    var engineerId;
    axios.get('http://localhost:8080/login/getUid', {
        withCredentials: true

    }).then(function(response){
        engineerId=response.data.data;
        console.log("这是工程师id:"+engineerId)
    }).catch(function(error) {
        console.log(document.cookie)
        // 请求失败的处理逻辑
        console.error(error);
    });


    layui.use(['form','layarea','layer'], function () {
        var form = layui.form,
            layarea = layui.layarea,
            layer = layui.layer,
            $ = layui.$;


        // 自定义验证规则
        form.verify({
            phoneOrEmpty: function(value, item) {
                // 判断是否为空
                if (value === '') {
                    return; // 不进行验证，直接通过
                }
                // 验证手机号格式
                var phoneReg = /^1[34578]\d{9}$/;
                if (!phoneReg.test(value)) {
                    return '请输入正确的手机号格式'; // 返回错误提示信息
                }
            }
        });

        var originalAddress;
        var updatedAddress;

        $.get('http://localhost:8080/engineer/' + engineerId, function(res) {

            data = res.data;
            layui.form.val('editForm', data);
            console.log("这是根据engineerId查询的data "+data)
            originalAddress = data.engineerProvince+data.engineerCity+data.engineerArea;
            layarea.render({
                elem: '#picker',

                data: {
                    province: data.engineerProvince,
                    city: data.engineerCity,
                    county: data.engineerArea,
                },
                change: function (res) {
                    // 选择结果
                    updatedAddress = res.province + res.city + res.county;
                    console.log(updatedAddress);
                }
            });
        })


        form.on('submit(saveBtn)', function (data) {
            event.preventDefault();


            layer.confirm('确认提交变动申请？', {
                btn: ['确定', '取消'], // 自定义按钮文本
                shadeClose: true
            }, function(index) {
                // 在这里执行接单的逻辑

                // axios.get('http://localhost:8080/order/takeOrder/'+orderId, {
                //     withCredentials: true
                //
                // })

                console.log(data)
                layer.msg("接单成功")
                layer.close(index); // 关闭确认窗口
            },function (index){

                layer.close(index)
            });


            // 地址没有改变，直接进行更新
            // $.ajax({
            //     url: 'http://localhost:8080/engineer',
            //     type: 'PUT',
            //     contentType: "application/json;charset=UTF-8",
            //     data: dataJson,
            //     success: function(response) {
            //         // 处理成功响应
            //         layer.msg("修改成功")
            //     },
            //     error: function(xhr, status, error) {
            //         layer.msg("修改失败")
            //     }
            // });




        });

        return false;
    });








</script>
</body>
</html>